package com.example.appjetpackcompose

import androidx.annotation.IdRes
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager

object ActivityUtilsKotlinExt {

    inline fun addFragmentToActivity(
        fragmentManager: FragmentManager, fragment: Fragment, @IdRes frameId: Int
    ) {
        val transaction = fragmentManager.beginTransaction()
        transaction.add(frameId, fragment)
        transaction.commitNow()
    }

    inline fun replaceFragmentToActivity(
        fragmentManager: FragmentManager, fragment: Fragment, @IdRes frameId: Int
    ) {
        val transaction = fragmentManager.beginTransaction()
        transaction.replace(frameId, fragment)
        transaction.commitNow()
    }

    inline fun removeFragmentToActivity(
        fragmentManager: FragmentManager, fragment: Fragment
    ) {
        val transaction = fragmentManager.beginTransaction()
        transaction.remove(fragment)
        transaction.commitNow()
    }
}